package org.kamionowski.supreme.persistence.entity;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Marcin Kamionowski
 * Date: 13.04.11
 * Time: 16:07
 */
@javax.persistence.Table(name = "search_file", schema = "public", catalog = "")
@NamedQueries(value = {
        @NamedQuery(name="deleteMarkedFilesForService", query = "DELETE FROM File f WHERE f.marked = true and f.service = :service"),
        @NamedQuery(name="markFilesForService", query = "SELECT f FROM File f WHERE f.service = :service"),
        @NamedQuery(name="selectByServiceAndPath", query = "SELECT f FROM File f WHERE f.service = :service AND f.dir = :dir AND f.name = :name")
})
@Entity
public class File implements Serializable{
    private Integer id;

    @javax.persistence.Column(name = "id", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
    @Id
    @SequenceGenerator(name="fileSeq")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    private Service service;

    @ManyToOne
    public
    @javax.persistence.JoinColumn(name = "service_id", referencedColumnName = "id", nullable = false)
    Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    private String name;

    @javax.persistence.Column(name = "name", nullable = false, insertable = true, updatable = true, length = 256, precision = 0)
    @Basic
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private String dir;

    @javax.persistence.Column(name = "dir", nullable = false, insertable = true, updatable = true, length = 400, precision = 0)
    @Basic
    public String getDir() {
        return dir;
    }

    public void setDir(String dir) {
        this.dir = dir;
    }

    private String ext;

    @javax.persistence.Column(name = "ext", nullable = true, insertable = true, updatable = true, length = 20, precision = 0)
    @Basic
    public String getExt() {
        return ext;
    }

    public void setExt(String ext) {
        this.ext = ext;
    }

    private Long fileSize;

    @javax.persistence.Column(name = "filesize", nullable = false, insertable = true, updatable = true, length = 19, precision = 0)
    @Basic
    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long size) {
        this.fileSize = size;
    }

    private Date modificationDate;

    @javax.persistence.Column(name = "date_modification", nullable = true, insertable = true, updatable = true, length = 13, precision = 0)
    @Basic
    public Date getModificationDate() {
        return modificationDate;
    }

    public void setModificationDate(Date date) {
        this.modificationDate = date;
    }

    private Boolean tmp;

    @javax.persistence.Column(name = "istmp", nullable = false, insertable = true, updatable = true, length = 1, precision = 0)
    @Basic
    public Boolean getTmp() {
        return tmp;
    }

    public void setTmp(Boolean tmp) {
        this.tmp = tmp;
    }

    private Boolean marked;

    @javax.persistence.Column(name = "ismarked", nullable = false, insertable = true, updatable = true, length = 1, precision = 0)
    @Basic
    public Boolean getMarked() {
        return marked;
    }

    public void setMarked(Boolean marked) {
        this.marked = marked;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        File that = (File) o;

        if (modificationDate != null ? !modificationDate.equals(that.modificationDate) : that.modificationDate != null) return false;
        if (dir != null ? !dir.equals(that.dir) : that.dir != null) return false;
        if (ext != null ? !ext.equals(that.ext) : that.ext != null) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (marked != null ? !marked.equals(that.marked) : that.marked != null) return false;
        if (tmp != null ? !tmp.equals(that.tmp) : that.tmp != null) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (service != null ? !service.equals(that.service) : that.service != null) return false;
        if (fileSize != null ? !fileSize.equals(that.fileSize) : that.fileSize != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (service != null ? service.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (dir != null ? dir.hashCode() : 0);
        result = 31 * result + (ext != null ? ext.hashCode() : 0);
        result = 31 * result + (fileSize != null ? fileSize.hashCode() : 0);
        result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
        result = 31 * result + (tmp != null ? tmp.hashCode() : 0);
        result = 31 * result + (marked != null ? marked.hashCode() : 0);
        return result;
    }
}
